package cn.wizzer.framework.filter;

import org.nutz.boot.AppContext;
import org.nutz.boot.starter.WebFilterFace;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

@IocBean
public class BizHandlerFilterStarter implements WebFilterFace {


    @Inject("refer:$ioc")
    protected Ioc ioc;

    @Inject
    protected PropertiesProxy conf;

    @Inject
    protected AppContext appContext;

    public String getName() {
        return "bizHandlerFilterStarter";
    }

    public String getPathSpec() {
        return "/*";
    }

    public EnumSet<DispatcherType> getDispatches() {
        return EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE);
    }

    @IocBean(name = "bizHandlerFilter")
    public BizHandlerFilter createRouteFilter() {
        return new BizHandlerFilter();
    }

    public Filter getFilter() {
        return ioc.get(BizHandlerFilter.class, "bizHandlerFilter");
    }

    public Map<String, String> getInitParameters() {
        return new HashMap<>();
    }

    public int getOrder() {
        return 1;
    }
}
